package com.stockz.ui.swing.charting.painter.indicator;

import java.awt.Graphics2D;

import com.stockz.ui.swing.charting.display.Displayable;
import com.stockz.ui.swing.charting.util.MathUtil;
import com.stockz.ui.swing.charting.util.UIChartingConstant;
import com.stockz.ui.swing.charting.view.StockChartPanelSkin;
import com.stockz.ui.swing.charting.view.StockChartPanelState;
import com.stockz.ui.swing.charting.view.StockRectangle;

public class IndicatorValuePainter{

	public static void paint(Graphics2D g, Displayable indicatorDisplay) {
			StockChartPanelState state =indicatorDisplay.getStockChartPanel().getStockChartPanelState();
			StockChartPanelSkin skin = indicatorDisplay.getStockChartPanel().getStockChartPanelSkin();
			
			StockRectangle rectangle = (StockRectangle)indicatorDisplay.getRectangle();
			double min = rectangle.getMinimumValueVisible();
			double max = rectangle.getMaximumValueVisible();
			g.setClip(null);
			g.setColor(skin.getAxisVolumeColor());
			int divisions = 4;
			double increment = (rectangle.getMaximumValueVisible() - rectangle.getMinimumValueVisible())/divisions;
			if(increment == 0){
				increment = rectangle.getMaximumValueVisible();
			}
			if(increment == 0){
				increment = 1;
			}
			int height = (int)g.getFont().getStringBounds("M", g.getFontRenderContext()).getHeight();
			while(min <= max){
				int Y = MathUtil.fitY(
						rectangle.y,
						rectangle.y + rectangle.height,
						rectangle.getMinimumValueVisible(),
						max, 
						min,
						state.isSemiLog());
				g.drawLine(rectangle.x+rectangle.width, Y, rectangle.x+rectangle.width+ skin.getShortTickLength(), Y);
				g.drawString(UIChartingConstant.priceNumberFormat.format(min), rectangle.x+rectangle.width+3, Y+height+3);
				min += increment;
			}
	}
}
